package com.gitee.feizns.v8.genertor;

import lombok.SneakyThrows;
import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;

import java.io.StringWriter;

public class TemplateGenerator {

    private Template template;

    public TemplateGenerator(Template template) {
        this.template = template;
    }

    /**
     * 生成模板
     * @param c
     * @return
     */
    @SneakyThrows
    String generate(VelocityContext c) {
        try (StringWriter sw = new StringWriter()) {
            template.merge(c, sw);
            return sw.toString();
        }
    }

}
